package com.mz.ozy.widget.dialog;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;

import com.mz.ozy.R;
import com.mz.ozy.activity.me.PayPwdActivity;
import com.mz.ozy.utils.ToastUtils;


public class PayPopupWindow extends BasePopupWindow implements View.OnClickListener {
    private OnClickListener mOnClickListener;
    EditText payPwdEt;
    private Context mContext;

    public PayPopupWindow(Context mContext, OnClickListener mOnClickListener) {
        super(mContext, R.layout.pop_pay_pwd, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
        this.mOnClickListener = mOnClickListener;
        this.mContext = mContext;
        init();
    }

    private void init() {

        getView(R.id.deleteIv).setOnClickListener(this);
        getView(R.id.confirmBt).setOnClickListener(this);
        getView(R.id.forgetPayPwdTv).setOnClickListener(this);
        payPwdEt = getView(R.id.payPwdEt);


    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {

            case R.id.deleteIv:
                dismiss();
                break;
            case R.id.confirmBt:
                if (TextUtils.isEmpty(payPwdEt.getText().toString().trim())) {
                    ToastUtils.showToast(mContext.getString(R.string.input_pay_pwd_hint));
                    return;
                }
                if (payPwdEt.getText().toString().trim().length() != 6) {
                    ToastUtils.showToast(mContext.getString(R.string.str_paypwd_format_hint));
                    return;
                }
                mOnClickListener.onConfirm(payPwdEt.getText().toString().trim());
                break;
            case R.id.forgetPayPwdTv:
                mContext.startActivity(new Intent(mContext, PayPwdActivity.class));
                break;
        }

    }

    public void setPwdEmpty() {
        payPwdEt.setText("");
    }

    public interface OnClickListener {
        void onConfirm(String pwd);
    }
}
